﻿Imports System
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Workflow.ComponentModel

Namespace System.Workflow.ComponentModel.Serialization
    Friend NotInheritable Class ActivityCodeDomReferenceService
        Implements IReferenceService
        ' Methods
        Public Sub New(ByVal referenceService As IReferenceService)
            Me.refService = referenceService
        End Sub

        Public Function GetComponent(ByVal reference As Object) As IComponent
            If (Not Me.refService Is Nothing) Then
                Return Me.refService.GetComponent(reference)
            End If
            Return Nothing
        End Function

        Public Function GetName(ByVal reference As Object) As String
            Dim activity As Activity = [TryCast](reference,Activity)
            If (Not activity Is Nothing) Then
                Return activity.QualifiedName.Replace("."c, "_"c)
            End If
            If (Not Me.refService Is Nothing) Then
                Return Me.refService.GetName(reference)
            End If
            Return Nothing
        End Function

        Public Function GetReference(ByVal name As String) As Object
            If (Not Me.refService Is Nothing) Then
                Return Me.refService.GetReference(name)
            End If
            Return Nothing
        End Function

        Public Function GetReferences() As Object()
            If (Not Me.refService Is Nothing) Then
                Return Me.refService.GetReferences
            End If
            Return Nothing
        End Function

        Public Function GetReferences(ByVal baseType As Type) As Object()
            If (Not Me.refService Is Nothing) Then
                Return Me.refService.GetReferences(baseType)
            End If
            Return Nothing
        End Function


        ' Fields
        Private refService As IReferenceService
    End Class
End Namespace

